import { defHttp } from '/@/utils/http/axios';
import { getMenuListResultModel } from './model/menuModel';

enum Api {
    GetMenuList = '/sys/permission/getUserPermissionByToken',
    getSPaceTree = "/foc/focSpace/getSPaceTree",
    focDeviceList = "/foc/focDevice/list",  //设备管理
    focPoint = "/foc/focPoint/list",  //点位管理
    getFilterOptions = "/foc/mDataConf/getFilterOptions",
    codeNameInfoListAll = "/foc/codeNameInfo/listAll"
    // 【QQYUN-8487】
    // SwitchVue3Menu = '/sys/switchVue3Menu',
}

/**
 * @description: Get user menu based on id
 */

export const getMenuList = () => {
    return new Promise((resolve) => {
        //为了兼容mock和接口数据
        defHttp.get<getMenuListResultModel>({ url: Api.GetMenuList }).then((res) => {
            if (Array.isArray(res)) {
                resolve(res);
            } else {
                resolve(res['menu']);
            }
        });
    });
};



export const getSPaceTree = () => {
    return new Promise((resolve) => {
        defHttp.get<any>({ url: Api.getSPaceTree }).then((res) => {
            resolve(res);
        });
    });
};

export const getFilterOptions = (queryType, mpBigType?: string, mpPorintType?: string, mpDeviceType?: string,codeAndName?: string) => {
    return new Promise((resolve) => {
        defHttp.post<any>({ url: Api.getFilterOptions, params: { queryType, mpBigType, mpPorintType, mpDeviceType,codeAndName } }).then((res) => {
            resolve(res);
        });
    });
}

export const codeNameInfoListAll = (type, nameAndCode) => {
    return new Promise((resolve) => {
        defHttp.post<any>({ url: Api.codeNameInfoListAll, params: { type, nameAndCode } }).then((res) => {
            resolve(res);
        });
    });
}

export const focDeviceList = (parentGuid: { parentGuid: string }) => {
    return new Promise((resolve) => {
        defHttp.get<any>({ url: Api.focDeviceList, params: parentGuid }).then((res) => {
            resolve(res);
        });
    });
};

export const focPoint = (parentGuid: { parentGuid: string }) => {
    return new Promise((resolve) => {
        defHttp.get<any>({ url: Api.focPoint, params: parentGuid }).then((res) => {
            resolve(res);
        });
    });
};






/**
 * @description: 获取后台菜单权限和按钮权限
 */
export function getBackMenuAndPerms() {
    return defHttp.get({ url: Api.GetMenuList });
}

/**
 * 切换成vue3菜单
 */
// update-begin--author:liaozhiyang---date:20240313---for：【QQYUN-8487】注释掉判断菜单是否vue2版本逻辑代码
// export const switchVue3Menu = () => {
//   return new Promise((resolve) => {
//     defHttp.get({ url: Api.SwitchVue3Menu });
//   });
// };
// update-end--author:liaozhiyang---date:20240313---for：【QQYUN-8487】注释掉判断菜单是否vue2版本逻辑代码
